package com.graduation.mybatis.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class NewsDTO {
    private Long newsId;
    private String title;
    private String content;
    private String category;
    private String publishTime;
    private List<String> images;
    private Integer commentCount;
    private Boolean isLiked;

    public NewsDTO(Long newsId,String title, String content, String category, Date publishTime, List<String> images, Integer commentCount, Boolean isLiked) {
        this.newsId = newsId;
        this.title = title;
        this.content = content;
        this.category = category;
        this.images = images;
        this.commentCount = commentCount;
        this.isLiked = isLiked;

        // 安全地格式化时间
        if (publishTime != null) {
            this.publishTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(publishTime);
        } else {
            this.publishTime = "暂无发布时间";
        }
    }
}